<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-02 19:42:06
 * @LastEditTime: 2022-08-25 21:34:16
 * @LastEditors: CHINAKAIYUAN
 * @Description: 
 */

namespace App\Repositories;

use App\Models\OpenCardGroundFabric;

class OpenCardGroundFabricRepository extends Repositories
    {
    public $relation_models = ["material", "creator", 'salesman', 'customer', 'unit', 'auditor', 'status'];
    public function boot(OpenCardGroundFabric $model)
        {
        $this->model = $model;
        }

    public function audit($v)
        {
        if ($v->status_id == 1) {
            fail("单据{$v['code']}{$v->status->name}，出库失败");
            }
        auditSave($v);
        $where = [
            'grade'       => ['key' => 'grade', 'default' => 'A'],
            'material_id' => ['key' => 'material_id'],
            'iscustomer'  => ['key' => 'customer_material'],
        ];
        if ($v->customer_material == 1) {
            $where['customer_id'] = $v->customer_id;
            }
        return $v->setWhere($where)->useStorage("生产领料")->subStorage();
        }
    public function noaudit($v)
        {
        if ($v->status_id == 0) {
            fail("单据{$v['code']}{$v->status->name}，取消出库失败");
            }
        auditSave($v, false);
        return $v->nosubStorage()->nouseStorage();
        }
    }
